from threading import Condition


import threading
class XioaAi(threading.Thread):
    def __init__(self,condition):
        super().__init__(name='小爱')
        self.condition=condition

    def run(self):
        with self.condition:
            self.condition.wait()#只有notify才能唤醒
            print(f'{self.name}: 在')
            self.condition.notify()#通知
            self.condition.wait()
            print(f'{self.name}: 好啊')

class TianMao(threading.Thread):
    def __init__(self,condition):
        super().__init__(name='天猫精灵')
        self.condition=condition
    def run(self):
        with self.condition:
            print(f'{self.name}:在吗，小爱同学')
            self.condition.notify()
            self.condition.wait()
            print(f'{self.name}:我们来对古诗吧，小爱同学')
            self.condition.notify()
            self.condition.wait()

#启动顺序很重要
if __name__ == '__main__':
    condition=Condition()
    xiaoai=XioaAi(condition)
    tianmao=TianMao(condition)

    xiaoai.start()
    tianmao.start()